package com.desire.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class FanoutConfig {

    /**
     * 向ioc窗口注入一个扇型交换器
     *
     * @return
     */
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("mq-sb-fanout");
    }


    //向ioc容器注入队列
    @Bean
    Queue queue() {
        return new Queue("mq-queue-one");
    }

    @Bean
    Queue queueTwo() {
        return new Queue("mq-queue-two");
    }


    //绑定队列1和交换器
    @Bean
    Binding binding(FanoutExchange exchange, @Qualifier("queue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange);
    }

    //绑定队列2和交换器
    @Bean
    Binding binding2(FanoutExchange exchange, @Qualifier("queueTwo") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange);
    }

}
